package com.lry.sso.service.ddd.controller;

import com.lry.sso.common.entity.response.ResultData;
import com.lry.sso.data.pojo.SysUser;
import com.lry.sso.service.ddd.feign.AuthFeign;
import com.lry.sso.service.ddd.service.LoginService;
import com.lry.sso.service.service.UserService;
import com.lry.sso.service.vo.LoginParamVo;
import com.lry.sso.service.vo.LoginResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 登录
 *
 * @author 李瑞益
 * @date 2019/11/30
 */
@RestController
@RequestMapping("sso/login/v1")
public class LoginController {

    @Autowired
    private AuthFeign authFeign;

    @Autowired
    private LoginService loginService;

//    @GetMapping("/public-key")
//    public ResultData<byte[]> getPublicKey(HttpServletRequest request){
//        byte[] result =  authFeign.getUserPublicKey();
//        return Ret.data(result);
//    }

    @PostMapping("/login")
    public ResultData<LoginResponseVo> login(@RequestBody LoginParamVo param, HttpServletResponse response){
        return loginService.login(param,response);
    }

    @GetMapping("/logout")
    public void logout(){
        loginService.logout();
    }


    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public void register(){
        String name = "liruiyi";
        String pwd = "123455";
        SysUser user = new SysUser();
        user.setUsername(name);
        user.setPassword(pwd);
        userService.insertUser(user);
    }
}
